﻿using UnityEngine;
using System;
/*
 弹框基类！
 */
namespace TinyFrameWork
{
    public class UIMessageBox : UIBaseWindow
    {
        private UILabel lbCenter;
        protected GameObject btnOK;
        protected GameObject btnCancle;
        protected GameObject btnService;
        protected GameObject btnClose;
        protected UISprite Icon;
        protected UILabel lbBtnMidTxt;

        public override void InitWindowOnAwake()
        {
            InitWindowData();
            base.InitWindowOnAwake();
            btnService = GameUtility.FindDeepChild(this.gameObject, "BtnService").gameObject;
            btnOK = GameUtility.FindDeepChild(this.gameObject, "BtnOK").gameObject;
            btnCancle = GameUtility.FindDeepChild(this.gameObject, "BtnCancle").gameObject;
            btnClose = GameUtility.FindDeepChild(this.gameObject, "BtnClose").gameObject;
            lbCenter = GameUtility.FindDeepChild<UILabel>(this.gameObject, "content-Label");
            lbBtnMidTxt = GameUtility.FindDeepChild<UILabel>(this.gameObject, "BtnService/Btn-Label");
            lbCenter.text = "";
        }

        public override void InitWindowData()
        {
            base.InitWindowData();
            this.windowData.windowType = UIWindowType.PopUp;
            this.windowData.showMode = UIWindowShowMode.DoNothing;
            this.windowData.colliderMode = UIWindowColliderMode.WithBg;
        }

        public override void ResetWindow()
        {
            base.ResetWindow();
            // 隐藏所有按钮
            NGUITools.SetActive(btnService, false);
            NGUITools.SetActive(btnCancle, false);
            NGUITools.SetActive(btnOK, false);
        }

        public override void ShowWindow()
        {
            NGUITools.SetActive(this.gameObject, true);
            IsLock = true;
        }

        public override void HideWindow(Action onComplete)
        {
            IsLock = true;
            NGUITools.SetActive(this.gameObject, false);
        }

        public virtual void SetCenterBtnCallBack(UIEventListener.VoidDelegate callBack)
        {
            NGUITools.SetActive(btnService, true);
            UIEventListener.Get(btnService).onClick = callBack;
        }

        public virtual void SetLeftBtnCallBack(UIEventListener.VoidDelegate callBack)
        {
            NGUITools.SetActive(btnCancle, true);
            UIEventListener.Get(btnCancle).onClick = callBack;
        }

        public virtual void SetRightBtnCallBack(UIEventListener.VoidDelegate callBack)
        {
            NGUITools.SetActive(btnOK, true);
            UIEventListener.Get(btnOK).onClick = callBack;
        }

        public void SetMsg(string msg)
        {
            lbCenter.text = msg;
        }

        public void SetSprite(string spritename)
        {
            Icon.spriteName = spritename;
        }

        public void SetMidBtnTxt(string name)
        {
            lbBtnMidTxt.text = name;
        }

        public void SetCanCleable(bool b)
        {
            if (b)
                btnClose.SetActive(true);
            else
                btnClose.SetActive(false);
        }
    }
}
